﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DelegatesAndEvents
{
    class Program
    {
        public delegate double Series();
        public static double DegreeIncrease()
        {
            double sum = 0;
            double tempSum=-1;
            double i = 1;
            while (string.Format("{0:0.00}", sum) != string.Format("{0:0.00}", tempSum))
            {
                tempSum =sum;
                sum =sum+1/ Math.Pow(i, 2);
                i++;
            }
            return sum;
        }
        public static double NumberIncrease()
        {
            double sum = 0;
            double tempSum = -1;
            double i = 0;
            while (string.Format("{0:0.00}", sum) != string.Format("{0:0.00}", tempSum))
            {
                tempSum = sum;
                sum = sum + 1 / Math.Pow(2, i);
                i++;
            }
            return sum;
        }
        public static double ExIncrease()
        {
            double sum = 0;
            double tempSum = -1;
            double i = 1;
            int j = 2;
            while (string.Format("{0:0.00}", sum) != string.Format("{0:0.00}", tempSum))
            {
                tempSum = sum;
                sum = sum + 1 / i;
                i=i*j;
                j++;
            }
            return sum;
        }
        static void Main(string[] args)
        {
            Series mySerie = new Series(DegreeIncrease);
            mySerie += ExIncrease;
            Console.WriteLine(string.Format("{0:0.00}",mySerie()));

        }
    }
}
